
package com.ukao.steward.pesenter.valetRunners;

import com.ukao.steward.base.BasePresenter;
import com.ukao.steward.bean.StringBean;
import com.ukao.steward.consts.Constant;
import com.ukao.steward.consts.SaveParams;
import com.ukao.steward.retrofit.ApiCallback;
import com.ukao.steward.view.valetRunners.BuildUserView;

import java.util.HashMap;

/**
 * Created by ukaodev on 2017/6/28.
 */

public class BuildUserPesenter extends BasePresenter<BuildUserView> {


    public BuildUserPesenter(BuildUserView view) {
        attachView(view);
    }





    /**
     获取验证码
     */
    public void testGetCode( String  phone) {
        mvpView.showLoading();
        HashMap mHashMap = new HashMap<String, String>();
        mHashMap.put("phone",phone);
        mHashMap.put("accessToken", SaveParams.getToken());
        addSubscription(apiStores.testGetCode(Constant.createParameter(mHashMap)),
                new ApiCallback<StringBean>() {
                    @Override
                    public void onSuccess(StringBean model) {

                        if (model.getHttpCode() == 200) {
                            if (model.isState()){

                                mvpView.loadVerifyCode();
                            }else{
                                mvpView.showError("发送失败");
                            }


                        }else{

                            mvpView.showError(model.getMsg());
                        }

                    }


                    @Override
                    public void onFinish() {

                        mvpView.hideLoading();

                    }
                });

    }

    /**
     添加用户
     */
    public void userInfoAdd( HashMap  mHashMap) {
        mvpView.showLoading();
        addSubscription(apiStores.userInfoAdd(Constant.createParameter(mHashMap)),
                new ApiCallback<StringBean>() {
                    @Override
                    public void onSuccess(StringBean model) {

                        if (model.getHttpCode() == 200) {
                              mvpView.userInfoAddSucceed(model.getMsg());
                        }else{

                            mvpView.showError(model.getMsg());
                        }

                    }


                    @Override
                    public void onFinish() {

                        mvpView.hideLoading();

                    }
                });

    }


}
